const express = require('express');
const router = express.Router()
const Blog = require('../../services/blogServices');




// 主页文章摘要请求
router.get("/abstract", async (req, res) => {
    const result = await Blog.getBlogs();
    res.send(result);
})


// 子页面响应(详细信息)
router.get("/details", async (req, res) => {
    const data = req.query;
    const result = await Blog.getBlogs(data.page, data.limit, {
        id: data.id
    });

    res.send(result)
})




router.get("/article_page", async (req, res) => {
    const data = req.query;
    console.log("🚀 ~ file: blogApi.js:28 ~ router.get ~ data:", data)
    const result = await Blog.getBlogs(data.page, data.limit, undefined, ['id', 'title', 'publishTime']);
    res.send(result);
})


// 添加博客
router.post("/addBlog", async (req, res) => {
    const result = await Blog.addBlog(req.body);
    res.send(result)
})



module.exports = router